package com.szholly.data.coderule.rules;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.szholly.utils.util.StringUtils;
import com.szholly.data.coderule.RuleService;
import com.szholly.data.general.*;

/// <summary>
/// 定义字段值编码规则
/// </summary>
@Component("CodeRule_10")
@Scope("prototype")
class FieldValueRule extends CodeRuleBase
{
    /// <summary>
    /// 获取代码规则值
    /// </summary>
    /// <param name="table">具体表</param>
    /// <param name="entity">要编码的实体</param>
    /// <param name="para">规则生成参数</param>
    /// <returns></returns>
	@Override
    public String GetCodeRule(ITable table, RowBase entity, String para, RowBase refEntity, String curCodeRule, String ruleInfoID)
    {
        String spring = RuleService.GetReplaceSpring(entity, para);
        if (StringUtils.IsNullOrSpace(spring))
            return "";
        else
        {
            Object value = RuleService.GetSpringValue(spring);
            if (value == null)
                return "";
            else
                return value.toString();
        }
    }
}
